/******************************************************************************
 * ----------------------------------------------------------------------------
 * ACA ASSIGNMENT 3: Simulation of MOESI cache coherence
 * Name: Shriram Gurumoorthy
 * GTID: 902535405
 * Email: shriram.g@gatech.edu
 *
 * This file provides the utility functions needed by the MOESI simulator
 * ----------------------------------------------------------------------------
 * ***************************************************************************/

#include "utils.h"

/******************************************************************************
 * function name: error
 * arguements: error message as a string
 * return: none
 * uses: Prints error message and exits
******************************************************************************/
void error(char *s)
{ printf("\nError: %s \n\nMOESI simulator exiting...\n\n", s);
  exit(1);
}

/******************************************************************************
 * function name: getBitCount
 * arguements: number for which the bit count has to be found
 * return: the bit that is set
 * uses: to find which bit is set in a number
******************************************************************************/
int getBitCount(int num)
{ int pow = 0;
  if(num <= 0)
    return -1;
  while(num > 1)
  { pow++;
    num = num>>1;
  }
  return pow;
}

/******************************************************************************
 * function name: powerOfTwo
 * arguements: number to which the power of 2 should be raised
 * return: 2^arguement
 * uses: finds 2^input
******************************************************************************/
int powerOfTwo(int num)
{ int pow = 1;
  int n=num;
  while(n)
  { pow = pow<<1;
    n--;
  }
  return pow;
}

/******************************************************************************
 * function name: checkForShare
 * arguements: the physical address
 * return: returns TRUE if shared or FALSE if not shared
 * uses: to find if a particular addr in memory is shared by caches 
******************************************************************************/
int checkForShare(int addr)
{
  /*run though the cache of every other proc 
   * and find out if this address is cached elsewhere*/
  return 1;
}

